package com.xtaller.core.helper;

import java.util.Random;
import java.util.UUID;

/**
 * Created by Tanj on 2017/6/7.
 * 字符串操作类
 */
public class StringHelper {

    /**
     * 随机生成字符串
     * @param length 表示生成字符串的长度
     * */
    public static String random(int length) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }
    /**
     * 随机生成6位数数字
     * */
    public static String randomNum() {
        Random r = new Random();
        return (r.nextInt(900000)+100000) +"";
    }
    /**
     * 利用UUID生成Token字符串
     * */
    public static String getToken(){
        String s = UUID.randomUUID().toString();
        //去掉“-”符号
        return s.substring(0,8)+s.substring(9,13)+s.substring(14,18)+s.substring(19,23)+s.substring(24);
    }

    /**
     * 数字格式化 前面补0
     * */
    public static String supplyNumber(int len,Object number){
        String supply = "";
        int size = number.toString().length();
        if(len > size){
            int x = len - size;
            for(int i=0;i<x;i++){
                supply += "0";
            }
            supply += number.toString();
            return supply;
        }
        return number.toString();
    }

//    public static void main(String[] arge){
//        System.out.println(supplyNumber(3,111));
//    }
}
